// fileName      :  error_code.go
// createdAt     :  2021-10-19
// description   :

package my_error

const (
	ErrorCodeSuccess = 1000 + iota
	ErrorCodeDataNotFound

	ErrorCodeEmptyToken
	ErrCodeInvalidToken
	ErrCodeTokenExpire

	ErrCodeParamError
	ErrCodeGetTokenFail
	ErrCodeRecordNotFound
	ErrCodeGeneralCode
	ErrCodeUserOrPwdFail
	ErrCodeGenerateIdFail
)

var codeMsgMap = map[int]string{
	ErrorCodeSuccess:      "success",
	ErrorCodeDataNotFound: "数据未找到",
	ErrorCodeEmptyToken:   "请求头中auth为空",
	ErrCodeInvalidToken:   "auth格式错误",
	ErrCodeParamError:     "参数错误",
	ErrCodeGetTokenFail:   "获取Token失败",
	ErrCodeRecordNotFound: "数据库找不到对应资源",
	ErrCodeGeneralCode:    "服务器发生内部错误",
	ErrCodeUserOrPwdFail:  "用户名或密码错误",
	ErrCodeGenerateIdFail: "生成唯一ID失败",
	ErrCodeTokenExpire:    "Token失效",
}

func getMsg(code int) string {
	if ok := codeMsgMap[code]; ok != "" {
		return ok
	}
	return "未知错误"
}
